<?php
class ViviendaAlquiler{
	
	public static function checkMinDate(){
		$stringDateStartLocation = sfConfig::get('app_date_start_location');
		$dateStartLocation = date($stringDateStartLocation);
		$today = date("d-m-Y");
		if(strtotime($today) < strtotime($dateStartLocation))
			return explode("-", $stringDateStartLocation);
		else
			return explode("-", $today);
	}
	
	public static function getSlugVivienda($apart_casa){
	  $aux = 'villa';
	  if($apart_casa == 0){
		$aux = 'appartement';
	  }
	  return $aux;
	}
	
	public static function getBrefSlug($apart_casa){
	  $aux = 'villa';
	  if($apart_casa == 0){
		$aux = 'appt.';
	  }
	  return $aux;
	}
	
	public static function getOppositeOrder($order){
	  $aux = 'asc';
	  if($order == 'asc'){
		$aux = 'desc';
	  }
	  return $aux;
	}
	
	public static function getTitleOrder($order, $crit){
	  $comment = 'Montrer de moins '.$crit.' &aacute; plus '.$crit;
	  if($order == 'asc'){
		$comment = 'Montrer de plus '.$crit.' &aacute; moins '.$crit;
	  }
	  return $comment;
	}
	
	/**
 * Modifies a string to remove al non ASCII characters and spaces.
 */
static public function slugify($text, $separator)
{
    $text = ViviendaAlquiler::stripAccents($text);
    // replace non letter or digits by -
    $text = preg_replace('~[^\\pL\d]+~u', $separator, $text);
 
    // trim
    $text = trim($text, '-');
 
    // transliterate
    if (function_exists('iconv'))
    {
        $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
    }
 
    // lowercase
    $text = strtolower($text);
 
    // remove unwanted characters
    $text = preg_replace('~[^-\w]+~', '', $text);
 
    if (empty($text))
    {
        return 'n-a';
    }
 
    return $text;
}

static function stripAccents($string) {
	$string = str_replace(
		array(
			'à', 'â', 'ä', 'á', 'ã', 'å',
			'î', 'ï', 'ì', 'í', 
			'ô', 'ö', 'ò', 'ó', 'õ', 'ø', 
			'ù', 'û', 'ü', 'ú', 
			'é', 'è', 'ê', 'ë', 
			'ç', 'ÿ', 'ñ',
			'À', 'Â', 'Ä', 'Á', 'Ã', 'Å',
			'Î', 'Ï', 'Ì', 'Í', 
			'Ô', 'Ö', 'Ò', 'Ó', 'Õ', 'Ø', 
			'Ù', 'Û', 'Ü', 'Ú', 
			'É', 'È', 'Ê', 'Ë', 
			'Ç', 'Ÿ', 'Ñ' 
		),
		array(
			'a', 'a', 'a', 'a', 'a', 'a', 
			'i', 'i', 'i', 'i', 
			'o', 'o', 'o', 'o', 'o', 'o', 
			'u', 'u', 'u', 'u', 
			'e', 'e', 'e', 'e', 
			'c', 'y', 'n', 
			'A', 'A', 'A', 'A', 'A', 'A', 
			'I', 'I', 'I', 'I', 
			'O', 'O', 'O', 'O', 'O', 'O', 
			'U', 'U', 'U', 'U', 
			'E', 'E', 'E', 'E', 
			'C', 'Y', 'N' 
		), $string);
	return $string;
}

  static function viviendaTitle($vivienda){
	$tipoVivienda = "Appartement";
	if($vivienda->getApart_casa() > 0){$tipoVivienda="Maison ";}
	$title = ucwords($vivienda->getSlug())." ".$vivienda->getAlias()." en location, avec ";
	if($vivienda->getPiscina() >0 ){
		$title = $title."piscine et ";
	}
	$title = $title.$vivienda->getHabitaciones()." chambres, ";
	$title = $title."pour ".$vivienda->getCapacidad()." personnes situe a ".$vivienda->getZona().", ".$vivienda->getZonasViviendas()->getMunicipio()." | Costa Bravas";
	return $title;
  }
  
    static function viviendaOfferTitle($vivienda){
	$tipoVivienda = "Appartement";
	if($vivienda->getApart_casa() > 0){$tipoVivienda="Maison ";}
	$title = ucwords($vivienda->getSlug())." ".$vivienda->getAlias()." en location, avec ";
	if($vivienda->getPiscina() >0 ){
		$title = $title."piscine et ";
	}
	$title = $title.$vivienda->getHabitaciones()." chambres, ";
	$title = $title."pour ".$vivienda->getCapacidad()." personnes situ&eacute &agrave; ".$vivienda->getZona().", ".$vivienda->getZonasViviendas()->getMunicipio();
	return $title;
  }
  
  static function viviendaPrecioConComision($precio){
	return $precio + + sfConfig::get('app_comision_euros');
  }
  
}


?>